jQuery.noConflict();
jQuery(document).ready(function($jvt_jQuery){
       $jvt_jQuery('#panel').jvtCpanel({
           showOn  : 'click', 
           stickTo : 'left'
       });
       $jvt_jQuery('#slider').jtSlider({
	   captionPadding  : '0',
           captionOpacity  : 0.6,
           displayDuration : 8000,
       });
       $jvtCpanel_sample_color = jQuery('.jvtCpanel a.jvtCpanel-sample-setting');
	$jvtCpanel_sample_color.click(function(){
		var jvtCpanel_option_value = jQuery(this).attr('rel');		
		if ( jQuery(this).hasClass('jvtCpanel-texture') ) {
			var jvtCpanel_texture_url = 'http://www.javatemplates.com/wp-content/files/texturebg/'+jvtCpanel_option_value+'texture.png';
			jQuery('body').css( { 'backgroundImage': 'url(' + jvtCpanel_texture_url + ')', 'backgroundRepeat' : 'repeat' } );
			jQuery.cookie('jvtCpanel_photostory_texture_url', jvtCpanel_texture_url);
		} else { 
			jQuery('body').css( 'backgroundColor', '#' + jvtCpanel_option_value );
			jQuery.cookie('jvtCpanel_photostory_bgcolor', jvtCpanel_option_value);
		}		
		return false;
	});

	var jvtCpanel_body_bgcolor = jQuery('body, #featured').css('backgroundColor'),
		jvtCpanel_body_bgcolor_parts = jvtCpanel_body_bgcolor.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	delete ( jvtCpanel_body_bgcolor_parts[0] );
	for (var i = 1; i <= 3; ++i) {
		jvtCpanel_body_bgcolor_parts[i] = parseInt(jvtCpanel_body_bgcolor_parts[i]).toString(16);
		if (jvtCpanel_body_bgcolor_parts[i].length == 1) jvtCpanel_body_bgcolor_parts[i] = '0' + jvtCpanel_body_bgcolor_parts[i];
	}
	var jvtCpanel_body_bgcolor_parts_hex = jvtCpanel_body_bgcolor_parts.join('');
	jQuery('#jvtCpanel-control-background').ColorPicker({
		color: jvtCpanel_body_bgcolor_parts_hex,
		onShow: function (colpkr) {
			jQuery(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			jQuery(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			jQuery('body').css('backgroundColor', '#' + hex);
			jQuery.cookie('jvtCpanel_photostory_bgcolor', hex);
		}
	});

	var jvtCpanel_header_font_elements = 'h1,h2,h3,h4,h5,h6,.post h3 a',
		jvtCpanel_header_font_elements_color = 'h1,h2,h3,h4,h5,h6,.post h3 a',
		jvtCpanel_body_font_elements = 'body',
		jvtCpanel_body_font_elements_color = 'body';

	jQuery('#jvtCpanel-control-headerfont_bg').ColorPicker({
		onShow: function (colpkr) {
			jQuery(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			jQuery(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			jQuery(jvtCpanel_header_font_elements_color).css('color', '#' + hex + ' !important');
			jQuery('').css('color', '#fff !important');
			jQuery.cookie('jvtCpanel_photostory_header_font_color', hex);
		}
	});

	jQuery('#jvtCpanel_control_header_font').change(function(){
		var jvtCpanel_header_font_value = jQuery(this).val(),
			jvtCpanel_link_tag_id = jvtCpanel_header_font_value.replace('+','_').toLowerCase();
		
		if ( !jQuery( 'link#' + jvtCpanel_link_tag_id ).length )
			jQuery('head').append("<link id='" + jvtCpanel_link_tag_id + "' href='http://fonts.googleapis.com/css?family="+jvtCpanel_header_font_value+"' rel='stylesheet' type='text/css' />");
		
		jQuery('head').append("<style type='text/css'>" + jvtCpanel_header_font_elements + " { font-family: '" + jvtCpanel_header_font_value.replace('+',' ') + "', Arial, sans-serif !important; }</style>");
		
		jQuery.cookie('jvtCpanel_photostory_header_font', jvtCpanel_header_font_value);
	});


	jQuery('#jvtCpanel-control-bodyfont_bg').ColorPicker({
		onShow: function (colpkr) {
			jQuery(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			jQuery(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			jQuery(jvtCpanel_body_font_elements_color).css('color', '#' + hex + ' !important');
			jQuery.cookie('jvtCpanel_photostory_body_font_color', hex);
		}
	});

	jQuery('#jvtCpanel_control_body_font').change(function(){
		var jvtCpanel_body_font_value = jQuery(this).val(),
			jvtCpanel_link_tag_id = jvtCpanel_body_font_value.replace('+','_').toLowerCase();
		
		if ( !jQuery( 'link#' + jvtCpanel_link_tag_id ).length )
			jQuery('head').append("<link id='" + jvtCpanel_link_tag_id + "' href='http://fonts.googleapis.com/css?family="+jvtCpanel_body_font_value+"' rel='stylesheet' type='text/css' />");
		
		jQuery('head').append("<style type='text/css'>" + jvtCpanel_body_font_elements + " { font-family: '" + jvtCpanel_body_font_value.replace('+',' ') + "', Arial, sans-serif !important; }</style>");
		
		jQuery.cookie('jvtCpanel_photostory_body_font', jvtCpanel_body_font_value);
	});
});
